home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3780 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.0 KB

  1. Path: colossus.holonet.net!russell
  2. From: russell@news.mdli.com (Russell Blackadar)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Struct as default arg?
  5. Date: 25 Jan 1996 23:46:35 GMT
  6. Organization: HoloNet National Internet Access System: 510-704-1058/modem
  7. Message-ID: <4e94or$5nu@colossus.holonet.net>
  8. References: <rplDLrDFr.35K@netcom.com>
  9. NNTP-Posting-Host: jubal.mdli.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Robert Laudati (rpl@netcom.com) wrote:
  13. : I would like to use a structure as a default args as follows:
  14.  
  15. : typedef struct { double x; double y; } Point;
  16.  
  17. : int Write( int n, char *s, Point p={0.0,0.0} );
  18.  
  19. Try this:
  20.    const Point pconst = {0.0,0.0};
  21.    int Write( int n, char *s, Point p = pconst );
  22.  
  23. BTW, I'd recommend const Point& for the third arg, instead of Point.
  24. This avoids copying the struct, which presumably you don't need to
  25. do (you're just outputting it).
  26.  
  27. Also, in C++, you can write
  28.  
  29.     struct Point { double x; double y; };
  30.  
  31. which IMO is preferable to a typedef, stylistically.
  32. --
  33. Russell Blackadar,   russell@mdli.com
  34.